/* *****************************************************************************

  Copyright (C), 2023-2023, Huawei Tech. Co., Ltd.

 ******************************************************************************
  File Name     : hisec_mpu_cmd_defs.h
  Version       : Initial Draft
  Created       : 2023/8/21
  Last Modified :
  Description   : secure commands between Driver and MPU/uCode
  Function List :
***************************************************************************** */

#ifndef HISEC_MPU_CMD_DEFS_H
#define HISEC_MPU_CMD_DEFS_H

#include "mpu_cmd_base_defs.h"

#ifndef BIG_ENDIAN
#define BIG_ENDIAN 0x4321
#endif

#ifndef LITTLE_ENDIAN
#define LITTLE_ENDIAN 0x1234
#endif

#define IPSEC_SML_TBL_BUF_MAX 768

/**
 * @brief HISec set ipsec offload mode command struct defination
 * @see HISEC_MPU_CMD_SET_IPSEC_OFFLOAD_MODE
 *
 */
struct hisec_cmd_ipsec_offload_mode {
    struct comm_info_head msg_head; /**< Common information head */
    u16 func_id;                    /**< Function id  */
    u8 offload_mode;                /**< Offload mode, 0: disable 1: xfrm offload 2:ipsec full offload */
    u8 rsvd1[5];
};

/**
 * @brief HISec set ipsec ctrl host command struct defination
 * @see HISEC_MPU_CMD_SET_IPSEC_CTRL_HOST
 *
 */
struct hisec_cmd_ipsec_ctrl_host {
    struct comm_info_head msg_head; /**< Common information head */
    u16 func_id;                    /**< IPSec Function ID */
    u16 host_id;                    /**< IPSec owner controller host */
    u8 rsvd1[4];
};

/**
 * @brief HISec crypto state description
 *
 */
struct hisec_crypto_stats {
    u64 cryrx_auth_err;     /**< Crypto rx authority error */
    u64 cryrx_tfc_pad_err;  /**< Crypto rx tfc pad error */
    u64 cryrx_other_err;    /**< Crypto rx other error */
    u64 crytx_bd_err;       /**< Crypto tx bd error */
    u64 crytx_len_err;      /**< Crypto tx length error */
};

/**
 * @brief HISec get crypto device states command struct defination
 * @see HISEC_MPU_CMD_GET_CRYPTO_STATS
 *
 */
struct hisec_cmd_cryptodev_stats {
    struct comm_info_head msg_head;     /**< Common information head */
    struct hisec_crypto_stats stats;    /**< Crypto device states */
};

/**
 * @brief HISec get ipsec item count command struct defination
 * @see HISEC_MPU_CMD_GET_IPSEC_ITEM_CNT
 *
 */
struct hisec_cmd_ipsec_item_cnt {
    struct comm_info_head msg_head; /**< Common information head */
    u32 sp_item_cnt;                /**< SP item count */
    u32 sa_item_cnt;                /**< SA item count */
    u16 func_id;                    /**< Function id */
    u16 pad;
};

/**
 * @brief IPSec SML table arguments, used by struct hisec_cmd_sml_table
 *
 */
typedef union {
    struct {
        u32 tbl_index;
        u32 cnt;
        u32 total_cnt;
        u32 pad;
    } tbl_arg;

    u32 args[4];
} ipsec_sml_tbl_args;

/**
 * @brief HISec get ipsec sad or spd command struct defination
 * @see HISEC_MPU_CMD_GET_IPSEC_SAD
 * @see HISEC_MPU_CMD_GET_IPSEC_SPD
 *
 */
struct hisec_cmd_sml_table {
    struct comm_info_head msg_head;     /**< Common information head */
    u16 func_id;                        /**< Function ID */
    u16 pad;
    u32 tbl_type;                       /**< SML table type, unused */
    ipsec_sml_tbl_args args;            /**< SML table arguments */
    u8 tbl_buf[IPSEC_SML_TBL_BUF_MAX];  /**< SML table data buffer */
};

#endif /** HISEC_MPU_CMD_DEFS_H */
